﻿<html>
	<head>
		<link rel="stylesheet" href="http://localhost:8080/Anagram/css/css.css" type="text/css"; charset=UTF-8">
	</head>
	
	<body>
	<%@ page import="util.*, objects.*, objects.*, dispatchers.*, java.util.*" %>
		<div id="main">
		
			<%!
				DBManager dbManager = new DBManager("anagram", "root", "root");
				DBArticleDispatcher articleDispatcher = new DBArticleDispatcher(dbManager, "articles");
			%>
			
			<%@ include file="/jsp/general/header.jsp"%>
			<%@ include file="/jsp/general/mainmenu.html"%>
			
		
		<div id="article">
		
			<% LinkedList<Article> articleList = articleDispatcher.getArticles();
				if(articleList!=null)
					for(int i=0; i<articleList.size(); i++){
						Article article = articleList.get(i);
						int lengthPost = (article.getBody().length()<200) ? article.getBody().length() : 200;
			%>
				
				<div class="post">
					<%= article.getTitle()%><br><hr>
					<%= article.getBody().substring(0, lengthPost)%>...<br>
					<a href="/Anagram/jsp/articles/article.jsp?articleID=<%= article.getArticleID()%>">Read more</a>
				</div>
				
			<%}%>
		</div>
		
		
		<%	if(session!=null){
				User userAdmin = (User)session.getAttribute("user");
				if(userAdmin!=null && userAdmin.getSecurityLevel()==3){%>
			<div class="rightmenu">
				<a href="/Anagram/editArticle?action=new">Новая статья</a>
			</div>
		<%}}%>
			
			
		<%@ include file="/jsp/general/bottom.jsp"%>
	</div>
	
	</body>
</html>